<Project DefaultTargets="Build" ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  
  <PropertyGroup>
    <SolutionFile>iRING.sln</SolutionFile>
    <DeploymentDir>Deployment</DeploymentDir>
    <iRINGAdapter>$(DeploymentDir)\iRINGAdapter</iRINGAdapter>
    <iRINGSandbox>$(DeploymentDir)\iRINGSandbox</iRINGSandbox>
    <AdapterServiceRoot>Adapter</AdapterServiceRoot>
    <AdapterServiceDir>$(AdapterServiceRoot)\AdapterService</AdapterServiceDir>
    <InterfaceServiceRoot>InterfaceService</InterfaceServiceRoot>
	  <SandboxServiceRoot>SandboxService</SandboxServiceRoot>
    <MappingEditorRoot>MappingEditor</MappingEditorRoot>
    <MappingEditorDir>$(MappingEditorRoot)\$(MappingEditorRoot).Web</MappingEditorDir>
    <RefDataEditorRoot>RefDataEditor</RefDataEditorRoot>
    <RefDataEditorDir>$(RefDataEditorRoot)\$(RefDataEditorRoot).Web</RefDataEditorDir>
    <RefDataServiceRoot>ReferenceData</RefDataServiceRoot>
    <RefDataServiceDir>$(RefDataServiceRoot)\ReferenceDataService</RefDataServiceDir>    
    <AdapterServiceDeploymentDir>$(iRINGAdapter)\AdapterService</AdapterServiceDeploymentDir>
    <InterfaceServiceDeploymentDir>$(iRINGAdapter)\InterfaceService</InterfaceServiceDeploymentDir>
    <AdapterToolsDeploymentDir>$(iRINGAdapter)\Tools</AdapterToolsDeploymentDir>
    <MappingEditorDeploymentDir>$(iRINGAdapter)\MappingEditor</MappingEditorDeploymentDir>
    <RefDataEditorDeploymentDir>$(iRINGSandbox)\RefDataEditor</RefDataEditorDeploymentDir>
    <RefDataServiceDeploymentDir>$(iRINGSandbox)\RefDataService</RefDataServiceDeploymentDir>
    <SandboxServiceDeploymentDir>$(iRINGSandbox)\SandboxService</SandboxServiceDeploymentDir>
    <SandboxToolsDeploymentDir>$(iRINGSandbox)\Tools</SandboxToolsDeploymentDir>
    <TortoiseSVNCmd>"C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe"</TortoiseSVNCmd>
    <MSTestCmd>"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe"</MSTestCmd>
  </PropertyGroup>
  
  <ItemGroup>
    <UnitTest Include="RefDataServiceTests">
      <TestContainer>/testcontainer:$(RefDataServiceRoot)\ReferenceDataService.Tests\bin\Debug\ReferenceDataService.Tests.dll</TestContainer>
    </UnitTest>
    <UnitTest Include="AdapterServiceTests">
      <TestContainer>/testcontainer:$(AdapterServiceRoot)\AdapterService.Tests\bin\Debug\AdapterService.Tests.dll /runconfig:AdapterService.testrunconfig</TestContainer>
    </UnitTest>
  </ItemGroup>

  <ItemGroup>
    <AdapterServiceDeployment
      Include="$(AdapterServiceDir)\**"
      Exclude="$(AdapterServiceDir).Tests\**;
               $(AdapterServiceDir)\bin\*.pdb;
               $(AdapterServiceDir)\obj\**;
               $(AdapterServiceDir)\Properties\**;
               $(AdapterServiceDir)\*.csproj;
               $(AdapterServiceDir)\*.user;
               $(AdapterServiceDir)\*.vspscc;
               $(AdapterServiceDir)\web.config;
               $(AdapterServiceRoot)\.svn\**;
               $(AdapterServiceRoot)\*\.svn\**;
               $(AdapterServiceRoot)\*\*\.svn\**;
               $(AdapterServiceRoot)\*\*\*\.svn\**;">
    </AdapterServiceDeployment>
    
    <!--
    <SemWebInterfaceServiceDeployment
      Include="$(InterfaceServiceRoot)\**"
      Exclude="$(InterfaceServiceRoot)\web.config;
               $(InterfaceServiceRoot)\.svn\**;
               $(InterfaceServiceRoot)\*\.svn\**;">
    </SemWebInterfaceServiceDeployment>
    -->
	
	  <InterfaceServiceDeployment
      Include="$(InterfaceServiceRoot)\**"
      Exclude="$(InterfaceServiceRoot)\.svn\**;
               $(InterfaceServiceRoot)\*\.svn\**;
               $(InterfaceServiceRoot)\*\*\.svn\**;
               $(InterfaceServiceRoot)\*\*\*\.svn\**;
               $(InterfaceServiceRoot)\*.log;">
    </InterfaceServiceDeployment>
	
	  <SandboxServiceDeployment
      Include="$(SandboxServiceRoot)\**"
      Exclude="$(SandboxServiceRoot)\.svn\**;
               $(SandboxServiceRoot)\*\.svn\**;
               $(SandboxServiceRoot)\*\*\.svn\**;
               $(SandboxServiceRoot)\*\*\*\.svn\**;
               $(SandboxServiceRoot)\*.log;">
    </SandboxServiceDeployment>
    
    <MappingEditorDeployment
      Include="$(MappingEditorDir)\**"
      Exclude="$(MappingEditorDir)\bin\*.pdb;
               $(MappingEditorDir)\obj\**;
               $(MappingEditorDir)\Properties\**;
               $(MappingEditorDir)\*.html;
               $(MappingEditorDir)\*.csproj;
               $(MappingEditorDir)\*.user;
               $(MappingEditorDir)\*.vspscc;
               $(MappingEditorDir)\web.config;
               $(MappingEditorDir)\.svn\**;
               $(MappingEditorDir)\*\.svn\**">
    </MappingEditorDeployment>
    
    <RefDataEditorDeployment
      Include="$(RefDataEditorDir)\**"
      Exclude="$(RefDataEditorDir)\bin\*.pdb;
               $(RefDataEditorDir)\obj\**;
               $(RefDataEditorDir)\Properties\**;
               $(RefDataEditorDir)\*.cs;
               $(RefDataEditorDir)\*.html;
               $(RefDataEditorDir)\*.csproj;
               $(RefDataEditorDir)\*.user;
               $(RefDataEditorDir)\*.vspscc;
               $(RefDataEditorDir)\web.config;
               $(RefDataEditorDir)\.svn\**;
               $(RefDataEditorDir)\*\.svn\**">
    </RefDataEditorDeployment>
    
    <RefDataServiceDeployment
      Include="$(RefDataServiceDir)\**"
      Exclude="$(RefDataServiceDir).Tests\**;               
               $(RefDataServiceDir)\bin\*.pdb;
               $(RefDataServiceDir)\obj\**;
               $(RefDataServiceDir)\Properties\**;
               $(RefDataServiceDir)\*.csproj;
               $(RefDataServiceDir)\*.user;
               $(RefDataServiceDir)\*.vspscc;
               $(RefDataServiceDir)\web.config;
               $(RefDataServiceRoot)\.svn\**;
               $(RefDataServiceRoot)\*\.svn\**;
               $(RefDataServiceRoot)\*\*\.svn\**;">
    </RefDataServiceDeployment>
    
    <AdapterToolsDeployment
      Include="ExternalBinaries\SemWeb\rdfstorage.exe;
               ExternalBinaries\SemWeb\SemWeb.dll;
               ExternalBinaries\SemWeb\SemWeb.SQLServerStore.dll;
               ExternalBinaries\SemWeb\Mono.GetOptions.dll;
               Libraries\iRINGLibrary\bin\Debug\iRINGLibrary.dll;
               Libraries\iRINGLibrary\bin\Debug\UtilityLibrary.dll;
               Utilities\EncryptCredentials\bin\Debug\EncryptCredentials.exe;
               Utilities\AdapterClient\bin\Debug\AdapterClient.exe;">
    </AdapterToolsDeployment>
    
    <SandboxToolsDeployment
      Include="ExternalBinaries\SemWeb\rdfstorage.exe;
               ExternalBinaries\SemWeb\SemWeb.dll;
               ExternalBinaries\SemWeb\SemWeb.SQLServerStore.dll;
               ExternalBinaries\SemWeb\Mono.GetOptions.dll;
               Libraries\iRINGLibrary\bin\Debug\iRINGLibrary.dll;
               Libraries\iRINGLibrary\bin\Debug\UtilityLibrary.dll;
               Utilities\EncryptCredentials\bin\Debug\EncryptCredentials.exe;
               Utilities\QMXFGenerator\QMXFGenerator\bin\Debug\QMXFGenerator.exe;
               Utilities\QMXFGenerator\QMXFGenerator\bin\Debug\Microsoft.Office.Interop.Excel.dll;
               Utilities\QMXFGenerator\QMXFGenerator\bin\Debug\Microsoft.Vbe.Interop.dll;
               Utilities\QMXFGenerator\QMXFGenerator\bin\Debug\office.dll;">
    </SandboxToolsDeployment>    
  </ItemGroup>

  <ItemGroup>
    <DeploymentPackage Include="*" Exclude="">
      <Path>$(iRINGAdapter)</Path>
      <Options>-r</Options>
      <ZIPFile>..\iRINGAdapter-110.zip</ZIPFile>
      <Source>*</Source>
    </DeploymentPackage>
    <DeploymentPackage Include="*" Exclude="">
      <Options>-r</Options>
      <Path>$(iRINGSandbox)</Path>
      <ZIPFile>..\iRINGSandbox-110.zip</ZIPFile>
      <Source>*</Source>
    </DeploymentPackage>
    <DeploymentPackage Include="*" Exclude="">
      <Options>-r</Options>
      <Path>$(iRINGAdapter)</Path>
      <ZIPFile>..\iRINGComponents-110.zip</ZIPFile>
      <Source>*</Source>
    </DeploymentPackage>
    <DeploymentPackage Include="*" Exclude="">
      <Options>-r -u</Options>
      <Path>$(iRINGSandbox)</Path>
      <ZIPFile>..\iRINGComponents-110.zip</ZIPFile>
      <Source>*</Source>
    </DeploymentPackage>
  </ItemGroup>

  <Target Name="SvnCleanUp">
    <Message Text="Performing SVN clean-up ..." />
    <Exec Command="$(TortoiseSVNCmd) /notempfile /command:cleanup /path:C:\iring.svn.codeplex.com /closeonend:1"/>
    <Message Text="Closing SVN clean-up diaglog ..." />
  </Target>
  
  <Target Name="SvnUpdate">
    <Message Text="Performing SVN update ..." />
    <Exec Command="$(TortoiseSVNCmd) /notempfile /command:update /path:C:\iring.svn.codeplex.com /closeonend:1"/>
  </Target>
  
  <Target Name="CoreBuild">
    <Message Text="Performing MSBuild ..." />
    <MSBuild Projects="$(SolutionFile)" Targets="Build"/>
  </Target>
  
  <Target Name="CleanBuild">
    <Message Text="Performing MSBuild clean-up ..." />
    <MSBuild Projects="$(SolutionFile)" Targets="Clean"/>
  </Target>
  
  <Target Name="Test">
    <Message Text="Cleaning old test results ..." />
    <Exec Command="RmDir /S /Q TestResults" />   
    <Message Text="Executing unit tests..." />
    <Exec Command="$(MSTestCmd) %(UnitTest.TestContainer)" />
  </Target>

  <Target Name="CreateDeployment">
    <Message Text="Cleaning up old deployment folders..." />
    <Exec Command="RmDir /S /Q $(DeploymentDir)" />
    <MakeDir Directories="$(DeploymentDir)/iRINGAdapter; $(DeploymentDir)/iRINGSandbox"/>

    <Message Text="Creating adapter service deployment ..." />
    <Copy SourceFiles="@(AdapterServiceDeployment)"
          DestinationFiles="@(AdapterServiceDeployment->'$(AdapterServiceDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Exec Command="Move /Y $(AdapterServiceDeploymentDir)\Web_Default.config $(AdapterServiceDeploymentDir)\Web.config" />

    <!--
    <Message Text="Creating SemWeb interface service deployment ..." />
    <Copy SourceFiles="@(SemWebInterfaceServiceDeployment)"
          DestinationFiles="@(SemWebInterfaceServiceDeployment->'$(SemWebInterfaceServiceDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Exec Command="Move /Y $(SemWebInterfaceServiceDeploymentDir)\Web_Default.config $(SemWebInterfaceServiceDeploymentDir)\Web.config" />
    -->
    <Message Text="Creating interface service deployment ..." />
    <Copy SourceFiles="@(InterfaceServiceDeployment)"
          DestinationFiles="@(InterfaceServiceDeployment->'$(InterfaceServiceDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Exec Command="Move /Y $(InterfaceServiceDeploymentDir)\setup.default.conf $(InterfaceServiceDeploymentDir)\setup.conf" />
    <Exec Command="Move /Y $(InterfaceServiceDeploymentDir)\webapps\joseki\WEB-INF\web.default.xml $(InterfaceServiceDeploymentDir)\webapps\joseki\WEB-INF\web.xml" />
    
    <Message Text="Creating mapping editor deployment ..." />
    <Copy SourceFiles="@(MappingEditorDeployment)"
          DestinationFiles="@(MappingEditorDeployment->'$(MappingEditorDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Exec Command="Move /Y $(MappingEditorDeploymentDir)\Web_Default.config $(MappingEditorDeploymentDir)\Web.config" />

    <Message Text="Creating reference data editor deployment ..." />
    <Copy SourceFiles="@(RefDataEditorDeployment)"
          DestinationFiles="@(RefDataEditorDeployment->'$(RefDataEditorDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Exec Command="Move /Y $(RefDataEditorDeploymentDir)\Web_Default.config $(RefDataEditorDeploymentDir)\Web.config" />

    <Message Text="Creating reference data service deployment ..." />
    <Copy SourceFiles="@(RefDataServiceDeployment)"
          DestinationFiles="@(RefDataServiceDeployment->'$(RefDataServiceDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Exec Command="Move /Y $(RefDataServiceDeploymentDir)\Web_Default.config $(RefDataServiceDeploymentDir)\Web.config" />
    <Exec Command="Move /Y $(RefDataServiceDeploymentDir)\XML\Repositories_Default.xml $(RefDataServiceDeploymentDir)\XML\Repositories.xml" />

    <Message Text="Creating sandbox service deployment ..." />
    <Copy SourceFiles="@(SandboxServiceDeployment)"
          DestinationFiles="@(SandboxServiceDeployment->'$(SandboxServiceDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
    <Exec Command="Move /Y $(SandboxServiceDeploymentDir)\setup.default.conf $(SandboxServiceDeploymentDir)\setup.conf" />
    <Exec Command="Move /Y $(SandboxServiceDeploymentDir)\webapps\joseki\WEB-INF\web.default.xml $(SandboxServiceDeploymentDir)\webapps\joseki\WEB-INF\web.xml" />
    
    <Message Text="Creating adapter tools deployment ..." />
    <Copy SourceFiles="@(AdapterToolsDeployment)"
          DestinationFiles="@(AdapterToolsDeployment->'$(AdapterToolsDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />

    <Message Text="Creating sandbox tools deployment ..." />
    <Copy SourceFiles="@(SandboxToolsDeployment)"
          DestinationFiles="@(SandboxToolsDeployment->'$(SandboxToolsDeploymentDir)\%(RecursiveDir)%(Filename)%(Extension)')" />
  </Target>

  <Target Name="CreatePackages" DependsOnTargets="CreateDeployment">
    <Exec Command="cd %(DeploymentPackage.Path) &amp;&amp; zip %(DeploymentPackage.Options) %(DeploymentPackage.ZIPFile) %(DeploymentPackage.Source)" />
  </Target>
  
  <Target Name="Build" DependsOnTargets="SvnUpdate; CoreBuild"/>
  
  <Target Name="Rebuild" DependsOnTargets="SvnUpdate; CleanBuild; CoreBuild"/>
  
  <Target Name="All" DependsOnTargets="Rebuild; Test; CreatePackages"/>
</Project>